home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / mess / MESS 0.133 / Macintosh / MessMenu 0.7.0 OSX uni.dmg / MessMenu.app / Contents / MacOS / messmenu.tcl < prev    next >
Encoding:
Text File  |  2009-04-16  |  11.6 KB  |  398 lines

  1. source mclistbox.tcl
  2. source getenv.tcl
  3. source filesel.tcl
  4. source about.tcl
  5. source prefs.tcl
  6.  
  7. set appdir [pwd]
  8. cd ../Resources
  9. set messdir [pwd]
  10. set MESSHOME [getenv MESSHOME [pwd]]
  11. cd "$messdir/../../.."
  12. set approot [pwd]
  13. set EDITOR [getenv EDITOR "open -t"]
  14. cd "$appdir"
  15.  
  16. wm title . "MessMenu"
  17.  
  18. #Declare that there is a menu
  19. menu .mbar
  20. . config -menu .mbar
  21. .mbar add cascade -label "Help" -underline 0 -menu [menu .mbar.help -tearoff 0]
  22. .mbar.help add command -label "About" -command { about }
  23. .mbar add cascade -label "MessMenu" -underline 0 -menu [menu .mbar.messmenu -tearoff 0]
  24. .mbar.messmenu add command -label "Preferences" -command { prefs }
  25. .mbar.messmenu add command -label "Edit mess.ini" -command { exec /bin/sh -c "$EDITOR '$MESSHOME/mess.ini'" }
  26. .mbar.messmenu add command -label "Reset all settings to default" -command { exec /bin/sh -c "sed 's%\.\./\.\./\.\.%$approot%' <'$messdir/mess.ini' >'$MESSHOME/mess.ini'"}
  27. .mbar.messmenu add command -label "Quit" -command { exit }
  28.  
  29. set system ""
  30.  
  31. #This function will be exected when the button is pushed
  32. proc startmess {} {
  33.     global skip fileselect messdir loadenable MESSHOME system device
  34.  
  35.     set currdir [pwd]
  36.     set args [.ent get]
  37.     if { $skip==-1 } {
  38.         set fskip "-autoframeskip"
  39.         set pskip "auto"
  40.     } else {
  41.         set fskip "-frameskip $skip"
  42.         set pskip $skip
  43.     }
  44.     set system_id [.lst curselection] ;#Get the no of the selected system
  45.     if { $system_id=={} } { ;#If there is no system
  46.         .txt delete 1.0 end
  47.         .txt insert end "No system selected!"
  48.     } else {
  49.         set temp [.lst get $system_id] ;#Get the name of the system
  50.         set system [lindex $temp 0]
  51.         set desc [lindex $temp 1]
  52.         set command "'$messdir/mess' $system $fskip $args"
  53.         set dir "../../../Software/$system"
  54.         if [catch {cd "$messdir/$dir"} errors] {
  55.             if [catch {cd "$messdir/../../../Software"} errors] {
  56.                 cd "$messdir/../../.."
  57.             }
  58.         }
  59.         set dir [pwd]
  60.         .txt delete 1.0 end
  61.         .txt insert end "System: $system\n"
  62.         .txt insert end "Description: $desc\n"
  63.         .txt insert end "Frame skip is: $pskip\n"
  64.         .txt insert end "Command: $command\n"
  65.         set devices ""
  66.         while { $loadenable == 1 } {
  67.             fileselect
  68.             tkwait window .fileSelectWindow
  69.             set diskfile $fileselect(selectedfile)
  70.             set dir [pwd]
  71.             if {$diskfile != "" } {
  72.                 if {$diskfile == ":UNLOAD:"} {
  73.                     set devices "$devices -$device \"\""
  74.                 } else {
  75.                     set devices "$devices -$device \"$dir/$diskfile\""
  76.                 }
  77.                 .txt insert end "$device: $diskfile\n"
  78.             }
  79. # Reselect current system
  80.             if { $system_id!={} } {
  81.                 .lst selection set $system_id
  82.             }
  83.         }
  84. # UGLY HACK
  85. # The following is part of a work around for a bug in mess 127 that affects
  86. # directory browsing.
  87. #        exec /bin/sh -c "rm -f '$MESSHOME/Software'/* >/dev/null 2>&1 ; exit 0"
  88. #        exec /bin/sh -c "ln * '$MESSHOME/Software' >/dev/null 2>&1 ; exit 0"
  89. # END UGLY HACK
  90.         cd "$MESSHOME"
  91.         set command "exec $command $devices"
  92.         if [catch {exec /bin/sh -c $command} output] {
  93.             .txt insert end "\nSDL Mess output:\n$output"
  94.         }
  95. # UGLY HACK REMed OUT
  96. # The following was part of a work around for a bug in mess 127 that corrupts
  97. # file paths. This is no longer needed as it is corrected in the patched
  98. # version of sdlmess that is included.
  99. # The following line has been replaced with a new version below
  100. #        exec /bin/sh -c "( test -f $system.ini && sed 's%\"$MESSHOME//%\"/%' <$system.ini | grep -v '^window ' | grep -v '^throttle ' | grep -v '^uimodekey ' | grep -v '^video ' >$system.ini.tmp 2>/dev/null ) ; exit 0"
  101. # END UGLY HACK REMed OUT
  102.  
  103. ###############################################################################
  104. # These lines prevent certain settings from being saved into every systems ini
  105. # file.
  106.         exec /bin/sh -c "( test -f $system.ini && grep -v '^window ' $system.ini | grep -v '^throttle ' | grep -v '^uimodekey ' | grep -v '^video ' >$system.ini.tmp 2>/dev/null ) ; exit 0"
  107.         exec /bin/sh -c "( test -f $system.ini.tmp && rm -f $system.ini 2>/dev/null ) ; exit 0"
  108.         exec /bin/sh -c "( test -f $system.ini.tmp && mv $system.ini.tmp $system.ini 2>/dev/null ) ; exit 0"
  109. ###############################################################################
  110.  
  111. # UGLY HACK
  112. # The following is part of a work around for a bug in mess 127 that affects
  113. # directory browsing.
  114. #        exec /bin/sh -c "rm -f '$MESSHOME/Software'/* >/dev/null 2>&1 ; exit 0"
  115. # END UGLY HACK
  116.     }
  117.     cd "$currdir"
  118. }
  119.  
  120. proc listinfo {} {
  121.     global appdir MESSHOME system messdir
  122.  
  123.     set currdir [pwd]
  124.     set system_id [.lst curselection] ;#Get the no of the selected system
  125.     if { $system_id=={} } { ;#If there is no system
  126.         .txt delete 1.0 end
  127.         .txt insert end "No system selected!"
  128.     } else {
  129.         set temp [.lst get $system_id] ;#Get the name of the system
  130.         set system [lindex $temp 0]
  131.         set desc [lindex $temp 1]
  132.         .txt delete 1.0 end
  133.         .txt insert end "System: $system\n"
  134.         .txt insert end "Description: $desc\n"
  135.         cd "$MESSHOME"
  136.         set command "exec '$appdir/messinfo.sh' '$system' 1>&2"
  137.         if [catch {exec /bin/sh -c $command} output] {
  138.             .txt insert end "\n$output"
  139.         }
  140.         if { [file exists "$messdir/sysinfo/$system.htm"] } {
  141.             exec open "$messdir/sysinfo/$system.htm"
  142.         }
  143.     }
  144.     cd "$currdir"
  145. }
  146.  
  147. proc doaudit {} {
  148.     global messdir MESSHOME system
  149.  
  150.     set currdir [pwd]
  151.     set system_id [.lst curselection] ;#Get the no of the selected system
  152.     if { $system_id=={} } { ;#If there is no system
  153.         .txt delete 1.0 end
  154.         .txt insert end "No system selected!"
  155.     } else {
  156.         set temp [.lst get $system_id] ;#Get the name of the system
  157.         set system [lindex $temp 0]
  158.         set desc [lindex $temp 1]
  159.         .txt delete 1.0 end
  160.         .txt insert end "System: $system\n"
  161.         .txt insert end "Description: $desc\n"
  162.         cd "$MESSHOME"
  163.         set command "exec '$messdir/mess' -verifyroms '$system' 1>&2"
  164.         if [catch {exec /bin/sh -c $command} output] {
  165.             .txt insert end "\n$output"
  166.         }
  167.         .txt insert end "\n"
  168.         set command "exec '$messdir/mess' -listroms '$system' 1>&2"
  169.         if [catch {exec /bin/sh -c $command} output] {
  170.             .txt insert end "\n$output"
  171.         }
  172.     }
  173.     cd "$currdir"
  174. }
  175.  
  176. #Global Variables
  177. set skip -1
  178. #GUI building
  179. frame .frm_args
  180. label .lab -text "Custom arguments:"
  181. entry .ent -width 80
  182. #Frame skip
  183. frame .frm_settings
  184. label .fslab -text "Frame skip (-1 = auto)"
  185. scale .frmskip -orient v -digit 1 -from -1 -to 10 \
  186.     -variable skip -tickinterval 1 -length 200
  187. #Load disk or cartridge
  188. checkbutton .load -text "Load/unload disk or cartridge" -variable loadenable
  189.  
  190. #System list
  191. frame .frm_system
  192. mclistbox::mclistbox .lst -selectmode single -yscrollcommand ".y set" -height 20 -width 80
  193. .lst column add sys -label "System" -width 10
  194. .lst column add desc -label "Description" -width 70
  195. scrollbar .y -command ".lst yview" -orient v
  196.  
  197.  
  198. button .but -text "Start" -command "startmess"
  199. button .info -text "Info" -command "listinfo"
  200. button .audit -text "Verify ROM" -command "doaudit"
  201.  
  202. #Text Area
  203. frame .textarea
  204. text .txt -yscrollcommand ".srl_y set" -xscrollcommand ".srl_x set" \
  205.     -width 110 -height 10
  206. scrollbar .srl_y -command ".txt yview" -orient v
  207. scrollbar .srl_x -command ".txt xview" -orient h
  208.  
  209. #Geometry Management
  210. grid .frm_args -in . -row 1 -column 1 -columnspan 4
  211. grid .lab -in .frm_args -row 1 -column 1
  212. grid .ent -in .frm_args -row 1 -column 2
  213. grid .frm_settings -in . -row 2 -column 1
  214. grid .fslab -in .frm_settings -row 1 -column 1
  215. grid .frmskip -in .frm_settings -row 2 -column 1
  216. grid .load -in .frm_settings -row 3 -column 1
  217. grid .frm_system -in . -row 2 -column 2 -columnspan 3
  218. grid .lst -in .frm_system -row 2 -column 1
  219. grid .y -in .frm_system -row 2 -column 2 -sticky ns
  220. grid .but -in . -row 4 -column 2 -sticky w
  221. grid .info -in . -row 4 -column 3 -sticky w
  222. grid .audit -in . -row 4 -column 4 -sticky w
  223. grid .txt   -in .textarea -row 1 -column 1
  224. grid .srl_y -in .textarea -row 1 -column 2 -sticky ns
  225. grid .srl_x -in .textarea -row 2 -column 1 -sticky ew
  226. grid .textarea -in . -row 5 -column 1 -columnspan 4
  227. #Adding systems
  228. source sysinfo.tcl
  229.  
  230. bind .lst <Up> {
  231.     set system_id [.lst curselection] ;#Get the no of the selected system
  232.     if {[llength $system_id] != 1} {
  233.         # Listbox has more or less than one selected item
  234.         return
  235.         }
  236.     .lst selection clear $system_id
  237.     incr system_id -1
  238.     if { $system_id < 0 } {
  239.         set system_id 0
  240.     }
  241.     .lst see $system_id
  242.     .lst selection set $system_id
  243.     break
  244. }
  245.  
  246. bind .lst <Down> {
  247.     set system_id [.lst curselection] ;#Get the no of the selected system
  248.     if {[llength $system_id] != 1} {
  249.         # Listbox has more or less than one selected item
  250.         return
  251.         }
  252.     .lst selection clear $system_id
  253.     set previous $system_id
  254.     incr system_id
  255.     .lst see $system_id
  256.     .lst selection set $system_id
  257.     set system_id [.lst curselection] ;#Get the no of the selected system
  258.     if {[llength $system_id] < 1} {
  259.         set system_id $previous
  260.         .lst see $system_id
  261.         .lst selection set $system_id
  262.     }
  263.     break
  264. }
  265.  
  266. bind .lst <Return> startmess
  267.  
  268. bind .lst <KeyPress> {
  269.     ListboxQuickSelect .lst %A
  270. }
  271.  
  272. bind .lst <1> {+ focus %W}
  273.  
  274. bind .frmskip <1> {+ focus %W}
  275.  
  276. bind .frmskip <KeyPress> {
  277.     set key "%A"
  278.     if {[string equal $key ""]} {
  279.         # %A substitute non unicode character by empty string
  280.         return
  281.     }
  282.     if { [string is integer $key] } {
  283.         set skip $key
  284.     }
  285.     if { [string equal $key -] } {
  286.         set skip -1
  287.     }
  288. }
  289.  
  290. # ----------------------------------------------------------------------
  291. #  ListboxQuickSelect --
  292. #
  293. #    This command implements quick positioning inside a listbox
  294. #    with key press. Each key pressed are buffered for the search.
  295. #
  296. #    Typical usage is through binding:
  297. #       bind $listbox <KeyPress> "ListboxQuickSelect %W %A"
  298. #
  299. # ----------------------------------------------------------------------
  300. proc ListboxQuickSelect {listbox key} {
  301.    upvar 0 ::ListboxQuickSelect:$listbox data
  302.  
  303.    if {[string equal $key ""]} {
  304.     # %A substitute non unicode character by empty string
  305.     return
  306.    }
  307.    set sel [$listbox curselection]
  308.    if {[llength $sel] > 1} {
  309.     # Listbox has more than one selected item
  310.     return
  311.    }
  312.  
  313.    # Initialize index where search begin
  314.    if {[llength $sel] == 1} {
  315.     set startIndex [lindex $sel 0]
  316.    } else {
  317.     set startIndex 0
  318.    }
  319.  
  320.    if {[info exists data(searchPrefix)]} {
  321.     set searchPrefix $data(searchPrefix)
  322.    } else {
  323.     set searchPrefix ""
  324.    }
  325.  
  326. #   if {[string equal -nocase $searchPrefix $key]} {
  327.     # User presses twice the same key for the first char.
  328.     # Search the next item which begin with that char (handled below).
  329. #   } else {
  330.     append searchPrefix $key
  331. #   }
  332.  
  333.    # Skip current selected item if searchPrefix is one char
  334.    # and selected item starts with this char.
  335. #   if {[llength $sel] == 1 &&
  336. #    [string length $searchPrefix] == 1 &&
  337. #    [string match -nocase "$searchPrefix*" \
  338. #         [ lindex [$listbox get $startIndex] 0 ]]} {
  339. #    incr startIndex
  340. #   }
  341.    .txt delete 1.0 end
  342.    .txt insert end "Searching for: $searchPrefix"
  343.  
  344.    # Now search for searchPrefix after current item,
  345.    # and wrap if not found.
  346.    foreach {start end} [list $startIndex end 0 $startIndex] {
  347.     set index $start
  348.     foreach item [$listbox get $start $end] {
  349.         set curritem [lindex $item 0]
  350.         if {[string match -nocase "$searchPrefix*" $curritem]} {
  351.         set newSelectedIndex $index
  352.         break
  353.         }
  354.         incr index
  355.     }
  356.  
  357.     if {[info exists newSelectedIndex]} {
  358.         # We have found a new item, select it and stop search
  359.         $listbox selection clear 0 end
  360.         $listbox selection set $newSelectedIndex
  361.         $listbox see $newSelectedIndex
  362.         break
  363.     }
  364.    }
  365.  
  366.    # Bufferize searchPrefix. Discard it in a small delay
  367.    if {[info exists data(afterId)]} {
  368.     after cancel $data(afterId)
  369.    }
  370.    set data(searchPrefix) $searchPrefix
  371.    set data(afterId)      [after 1000 "unset ::ListboxQuickSelect:$listbox"]
  372. }
  373.  
  374. foreach event {<KeyPress> <<PasteSelection>>} {bind .txt $event break}
  375.  
  376. bind .txt <Command-c> { event generate .txt <<Copy>> }
  377.  
  378. bind .txt <Up> {
  379.    .txt yview scroll -1 units
  380. }
  381.  
  382. bind .txt <Down> {
  383.    .txt yview scroll 1 units
  384. }
  385.  
  386. bind .txt <Left> { 
  387.    .txt xview scroll -1 units
  388. }
  389.  
  390. bind .txt <Right> {
  391.    .txt xview scroll 1 units
  392. }
  393.  
  394. #.lst selection clear 0 end
  395. #.lst selection set 0
  396. #.lst see 0
  397. #focus -force .lst
  398.